package com.wandian.cqcsk.adapter.mine;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.wandian.cqcsk.R;

import java.util.ArrayList;
import java.util.List;

public class HelpAndSuggesGridViewAdapter extends BaseAdapter {

    List<String> titles = new ArrayList<>();
    List<Integer> picIds = new ArrayList<>();
    Context context;
    public HelpAndSuggesGridViewAdapter(Context context, List<String> title, List<Integer> picId){
        this.titles =title;
        this.picIds =picId;
        this.context =context;
    }
    @Override
    public int getCount() {
        return titles == null ? 0 : titles.size();
    }

    @Override
    public Object getItem(int i) {
        return titles.get(i);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int index, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(convertView==null){
            // 重新填充note_item部局，并把它作为项的view返回
            convertView = LayoutInflater.from(context).inflate(R.layout.item_help_and_suggest_grid, null);
            viewHolder = new ViewHolder();
            viewHolder.textView = convertView.findViewById(R.id.tv_grid);
            viewHolder.imageView = convertView.findViewById(R.id.iv_grid);
            convertView.setTag(viewHolder);
        }else {
            viewHolder=(ViewHolder)convertView.getTag();
        }

        viewHolder.textView.setText(titles.get(index));
        viewHolder.imageView.setBackgroundResource(picIds.get(index));
        return convertView;
    }
    public class ViewHolder{
        TextView textView;
        ImageView imageView;
    }

}
